package com.dyz.leetcode._10_slidingWindow;

public class _1004_longestOnes {
    public int longestOnes(int[] nums, int k) {
        int ans = 0;
        int left=0, right =0;
        int windowCnt = 0;
        while(right<nums.length){
            if(nums[right]==0){
                windowCnt++;
                if(windowCnt==k+1){
                    ans = Math.max(ans, right-left);
                }
            }
            while (windowCnt>k){
                if(nums[left]==0) {windowCnt--;}
                left++;
            }
            right++;
        }
        return Math.max(ans, right-left);

    }
}
